﻿@{
    Layout = null;
}
@model ElingOA6_Admin_DSJCJ.Model.PrvUser
<!DOCTYPE html>
<html>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<head>
    <title>用户</title>
    @Html.Partial("LoadPanelPartial")
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/jquery-ui.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/PageCommon.js", true)" type="text/javascript"></script>

    <link href="@Url.Content("~/Scripts/dynatree/skin/ui.dynatree.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/dynatree/jquery.dynatree.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/json2.js", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)
    <style type="text/css">
        ul.dynatree-container
        {
            padding: 0px;
        }
    </style>

    <script type="text/javascript">
       
        var dataFunc = @Html.Raw(Json.Encode(ViewData["treeJsonStrUserFunc"]));
        if (dataFunc!="")
            {
                dataFunc=JSON.parse(dataFunc);
            }
            else
            {
                dataFunc=null;
            }
        
    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#toolMenu").smartFloat();

            $("#functionTree").dynatree({
                clickFolderMode: 1,
                selectMode: 3,
                children: dataFunc,
                keyboard: false,
                checkbox: false
            });


            var hdjsAlert = $("#hdjsAlert").val();
            if (hdjsAlert != "") {
                alert(hdjsAlert);
            }
        });
        /*保存*/
        function save() {
            var isCtlAllValid = true;
            var errorText = "";
            ASPxClientEdit.ValidateEditorsInContainer(null);
            var clientFLogIDObj = ASPxClientTextBox.Cast("FLogID");
            if (!clientFLogIDObj.GetIsValid()) {
                isCtlAllValid = false;
                errorText += clientFLogIDObj.GetErrorText() + "\n";

            }
            var clientFUserNameObj = ASPxClientTextBox.Cast("FUserName");
            if (!clientFUserNameObj.GetIsValid()) {
                isCtlAllValid = false;
                errorText += clientFUserNameObj.GetErrorText() + "\n";

            }
            var clientFEmpNameObj = ASPxClientButtonEdit.Cast("FEmpName");
            if (!clientFEmpNameObj.GetIsValid()) {
                isCtlAllValid = false;
                errorText += clientFEmpNameObj.GetErrorText() + "\n";

            }

            if (isCtlAllValid) {
                checkedNodes = new Array();
                if (typeof (orgUserTree) != "undefined") {
                    ListCheckedOrgUserNodes(orgUserTree);
                }
                if (checkedNodes.length > 0) {
                    $("#hdOrgUserSelect").val(checkedNodes.join(","));
                }
                checkedNodes = new Array();
                //                if (typeof (functionTree) != "undefined") {
                //                    ListCheckedFunctionNodes(functionTree);
                //                }
                if (checkedNodes.length > 0) {
                    $("#hdFunctionSelect").val(checkedNodes.join(","));
                }

                lpModal.Show();
                clientFLogIDObj.SetEnabled(true);
                ASPxClientCheckBox.Cast("FForeverAvailable").SetEnabled(true);
                ASPxClientDateEdit.Cast("FAvailableDate").SetEnabled(true);
                form1.submit();
            }
            else {
                alert(errorText);
            }

        }

        //员工选择确定
        function EmpOK(v, n) {
            $('#FEmplNo').val(v);
            var clientFEmpNameObj = ASPxClientButtonEdit.Cast("FEmpName");
            clientFEmpNameObj.SetText(n);
            pcModalMode.Hide();
        }
        //员工选择取消
        function EmpCancel() {
            pcModalMode.Hide();
        }
        function isAvailable() {
            $("#FProhibitLogin").click(function () {
                if (!!$("#FProhibitLogin").attr("checked")) {
                    $('#FPubDate').hide();
                }
                else {
                    $('#FPubDate').show();
                }
            });
        }

        /*增加*/
        function addGroup() {
            lp.Show();
            window.location.href = "AddGroup";
        }
        /*删除*/
        function deleteGroup() {
            var userName = FUserName.GetText();
            var hdFLogIDEn = $("#hdFLogIDEn").val();
            if (confirm("确定删除【" + userName + "】吗？")) {
                $.ajax({
                    type: "POST",
                    url: "DeleteUser",
                    data: { userIDEn: hdFLogIDEn },
                    async: true,
                    success: function (jsonstr) {
                        var msg = jsonstr.split('|');
                        if (msg[0] == "SUCCESS") {
                            alert("删除成功");
                            parent.afterDeleteNode();
                        }
                        else {
                            if (msg.length > 1) {
                                alert(msg[1]);
                            }
                        }
                    }
                });
            }
        }
        /*密码重置*/
        function ResetPwd() {
            var hdFLogIDEn = $("#hdFLogIDEn").val();
            if (confirm("确定重置密码？")) {
                $.ajax({
                    type: "POST",
                    url: "ResetPwd",
                    data: { userIDEn: hdFLogIDEn },
                    async: true,
                    success: function (jsonstr) {
                        var msg = jsonstr.split('|');
                        if (msg[0] == "SUCCESS") {
                            alert("重置成功");
                        }
                        else {
                            if (msg.length > 1) {
                                alert(msg[1]);
                            }
                        }
                    }
                });
            }
        }
        var checkedNodes;
        /*用户树*/
        function ListCheckedOrgUserNodes(parent) {
            for (var i = 0; i < parent.GetNodeCount(); i++) {
                if (parent.GetNode(i).GetChecked()) {
                    var node = parent.GetNode(i);
                    var nodeids = node.name.split("|");
                    if (nodeids.length > 1) {
                        if (nodeids[0] == "user") {
                            checkedNodes.push(nodeids[1]);
                        }
                    }
                }
                if (parent.GetNode(i).GetNodeCount() != 0) {
                    ListCheckedOrgUserNodes(parent.GetNode(i));
                }
            }
        }
        /*权限树*/
        //        function ListCheckedFunctionNodes(parent) {
        //            for (var i = 0; i < parent.GetNodeCount(); i++) {
        //                if (parent.GetNode(i).GetChecked() || parent.GetNode(i).GetCheckState() == "Indeterminate") {
        //                    var node = parent.GetNode(i);
        //                    var nodeids = node.name.split("|");
        //                    if (nodeids.length > 1) {
        //                        checkedNodes.push(nodeids[1]);
        //                    }
        //                }
        //                if (parent.GetNode(i).GetNodeCount() != 0) {
        //                    ListCheckedFunctionNodes(parent.GetNode(i));
        //                }
        //            }
        //        }

        /*节点选中*/
        function orgUserTreeInit() {
            var node = orgUserTree.GetSelectedNode();
            var loginIDs = $("#hdgroupNos").val();
            if (loginIDs != "") {
                var loginIDArray = loginIDs.split(",");
                for (var i = 0; i < loginIDArray.length; i++) {
                    var node = orgUserTree.GetNodeByName("user|" + loginIDArray[i]);
                    if (node) {
                        node.SetChecked(true);
                    }
                }
            }
        }
        //        function functionTreeInit() {
        //            var node = functionTree.GetSelectedNode();
        //            var functionNOs = $("#hddirGroupNos").val();
        //            if (functionNOs != "") {
        //                var functionNOsArray = functionNOs.split(",");
        //                for (var i = 0; i < functionNOsArray.length; i++) {
        //                    var node = functionTree.GetNodeByName("child|" + functionNOsArray[i]);
        //                    if (node) {
        //                        node.SetChecked(true);
        //                    }
        //                }
        //            }
        //        }
        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnSave":
                    {
                        //保存
                        save();
                        break;
                    }
                case "btnAdd":
                    {
                        //增加同级
                        addGroup();
                        break;
                    }

                case "btnDelete":
                    {
                        //删除
                        deleteGroup();
                        break;
                    }
                case "btnPwdReset":
                    {
                        //密码重置
                        ResetPwd();
                        break;
                    }
            }
        }
        function FEmplNo_ButtonClick(s, e) {
            switch (e.buttonIndex) {
                case 0:
                    pcModalMode.Show();
                    break;

            }
        }
        function FProhibitLogin_CheckedChanged(s, e) {
            var clientObj = ASPxClientCheckBox.Cast(s);
            var clientFForeverAvailableObj = ASPxClientCheckBox.Cast("FForeverAvailable");
            var clientFAvailableDateObj = ASPxClientDateEdit.Cast("FAvailableDate");
            if (clientObj.GetChecked()) {
                clientFForeverAvailableObj.SetEnabled(false);
                clientFForeverAvailableObj.SetChecked(false);
                clientFAvailableDateObj.SetEnabled(false);
                clientFAvailableDateObj.SetText("");
            }
            else {
                clientFForeverAvailableObj.SetEnabled(true);
                clientFAvailableDateObj.SetEnabled(true);
            }

        }
        function FForeverAvailable_CheckedChanged(s, e) {
            var clientObj = ASPxClientCheckBox.Cast(s);
            var clientFAvailableDateObj = ASPxClientDateEdit.Cast("FAvailableDate");
            if (clientObj.GetChecked()) {
                clientFAvailableDateObj.SetEnabled(false);
                clientFAvailableDateObj.SetText("");
            }
            else {
                clientFAvailableDateObj.SetEnabled(true);
            }
        }
    </script>

</head>
<body>
    @using (Html.BeginForm("Save", "User", FormMethod.Post, new { id = "form1", @class = "edit_form" }))
    {
        <div class="floatToolMenu" id="toolMenu">
            @Html.DevExpress().Menu(settings =>
   {
       settings.Name = "toolBarMenu";
       settings.ItemAutoWidth = false;
       settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
       settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
       settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
       settings.Items.Add(item =>
       {
           item.Name = "btnSave";
           item.Text = "保存";
           item.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");
       });
       settings.Items.Add(item =>
       {
           item.Name = "btnAdd";
           item.Text = "新增";
           item.Image.Url = Url.Content("~/Content/ControlImages/edit_add.png");
       });
       settings.Items.Add(item =>
       {
           item.Name = "btnDelete";
           item.Text = "删除";
           item.ItemStyle.ForeColor = System.Drawing.Color.Red;
           item.Image.Url = Url.Content("~/Content/ControlImages/cancel.png");

       });
       settings.Items.Add(item =>
       {
           item.Name = "btnPwdReset";
           item.Text = "密码重置";
           item.Image.Url = Url.Content("~/Content/ControlImages/reload.png");
       });
       settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
       settings.ItemLinkMode = ItemLinkMode.ContentBounds;
   }).GetHtml()
        </div>
        <div>
            <table align="center" class="tableForm">
                <tr>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "用户登录ID:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FLogID";
                       settings.Width = 220;
                       settings.Text = Model.FLogID;
                       settings.ClientEnabled = ViewData["hdMethod"].ToString() == "EDIT" ? false : true;
                       settings.Properties.ClientSideEvents.Validation = "function(s,e){notEmptyValidation(s,e,'用户登录ID')}";
                   }).GetHtml()
                    </td>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "用户名称:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FUserName";
                       settings.Width = 220;
                       settings.Text = Model.FUserName;
                       settings.Properties.ClientSideEvents.Validation = "function(s,e){notEmptyValidation(s,e,'用户名称')}";
                   }).GetHtml()
                    </td>
                </tr>
                <tr>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "属性:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().CheckBox(settings =>
                   {
                       settings.Name = "FProhibitLogin";
                       settings.Text = "禁止登录";
                       settings.ControlStyle.CssClass = "button";
                       settings.Checked = Model.FProhibitLogin == 1 ? true : false;
                       settings.Properties.ClientSideEvents.CheckedChanged = "FProhibitLogin_CheckedChanged";

                   }
                        ).GetHtml()
                        @Html.DevExpress().CheckBox(settings =>
                   {
                       settings.Name = "FForeverAvailable";
                       settings.Text = "永久有效";
                       settings.ControlStyle.CssClass = "button";
                       if (Model.FProhibitLogin == 1)
                       {
                           settings.ClientEnabled = false;
                           settings.Checked = false;
                       }
                       else
                       {
                           settings.ClientEnabled = true;
                           settings.Checked = Model.FForeverAvailable == 1 ? true : false;
                       }
                       settings.Properties.ClientSideEvents.CheckedChanged = "FForeverAvailable_CheckedChanged";
                   }).GetHtml()
                    </td>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "有效日期:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().DateEdit(settings =>
                   {
                       settings.Name = "FAvailableDate";
                       settings.Properties.NullText = "";

                       settings.Properties.DisplayFormatString = "yyyy-MM-dd";
                       settings.Properties.EditFormatString = "yyyy-MM-dd";
                       if (Model.FForeverAvailable == 1 || Model.FProhibitLogin == 1)
                       {
                           settings.ClientEnabled = false;
                       }
                       else
                       {
                           settings.ClientEnabled = true;
                           if (Model.FAvailableDate.HasValue)
                           {
                               settings.Date = Model.FAvailableDate.Value;
                           }
                       }
                   }).GetHtml()
                    </td>
                </tr>
                <tr>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "登录次数:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FLoginCnt";
                       settings.Width = 220;
                       settings.Text = Model.FLoginCnt.ToString();
                       settings.ClientEnabled = false;
                   }).GetHtml()
                    </td>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "最后登录IP:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FLastLoginIPAddr";
                       settings.Width = 220;
                       settings.ClientEnabled = false;
                       settings.Text = Model.FLastLoginIPAddr;
                   }).GetHtml()
                    </td>
                </tr>
                <tr>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "最后登录时间:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FLastLoginTime";
                       settings.Width = 220;
                       settings.ClientEnabled = false;
                       settings.Text = Model.FLastLoginTime != null ? Model.FLastLoginTime.Value.ToString("yyyy-MM-dd") : "";
                   }).GetHtml()
                    </td>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "对应员工:"; }).GetHtml()
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().ButtonEdit(settings =>
                   {
                       settings.Name = "FEmpName";
                       settings.Width = 220;
                       settings.ReadOnly = true;
                       settings.Properties.Buttons.Add("选择");
                       settings.Properties.ClientSideEvents.ButtonClick = "FEmplNo_ButtonClick";
                       settings.Properties.ClientSideEvents.Validation = "function(s,e){notEmptyValidation(s,e,'对应员工')}";
                   }).Bind(Model.FEmpName).GetHtml()
                        @Html.Hidden("FEmplNo", Model.FEmplNo)
                    </td>
                </tr>
                <tr>
                    <th>
                    </th>
                    <td class="tdClass">
                        @Html.DevExpress().CheckBox(
                    settings =>
                    {
                        settings.Name = "FIsLookAllDaily";
                        settings.Checked = Model.FIsLookAllDaily == "Y" ? true : false;
                        settings.Text = "允许查看全局绩效台账";
                    }).GetHtml()
                    </td>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "批示权限:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().CheckBox(
                    settings =>
                    {
                        settings.Name = "FIsInstruct";
                        settings.Checked = Model.FIsInstruct == "Y" ? true : false;
                        settings.Text = "领导批示";
                    }).GetHtml()
                    </td>
                </tr>
            </table>
        </div>  
        @Html.DevExpress().PopupControl(
    settings =>
    {
        settings.Name = "pcModalMode";
        settings.Width = 300;
        settings.Height = 430;
        settings.AllowDragging = true;
        settings.CloseAction = CloseAction.CloseButton;
        settings.EnableAnimation = false;
        settings.HeaderText = "人员选择";
        settings.Modal = true;
        settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
        settings.ShowFooter = true;
        settings.SetFooterTemplateContent(s =>
            {
                ViewContext.Writer.Write("<table align='center'><tr><td>");
                @Html.DevExpress().Button(footBtnSettings =>
                {
                    footBtnSettings.Name = "btnOK";
                    footBtnSettings.Text = "确定";
                    footBtnSettings.ClientSideEvents.Click = "function(s,e){popContent.OK()}";
                    footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
                    footBtnSettings.CausesValidation = false;
                }).GetHtml();
                ViewContext.Writer.Write("</td><td>");
                @Html.DevExpress().Button(footBtnSettings =>
              {
                  footBtnSettings.Name = "btnCancel";
                  footBtnSettings.Text = "取消";
                  footBtnSettings.ClientSideEvents.Click = "function(){EmpCancel();}";
                  footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                  footBtnSettings.CausesValidation = false;
              }).GetHtml();
                ViewContext.Writer.Write("</td></tr></table>");

            });
        settings.SetContent(() =>
        {
            ViewContext.Writer.Write("<iframe  id='popContent' name='popContent' style='width:100%;height:330px' frameborder='0' src='" + Url.Action("EmpData", "Dept") + "'></iframe>");
        });


    }).GetHtml()

        @Html.DevExpress().PageControl(
    settings =>
    {
        settings.Name = "tabCtlGroup";
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(99);
        //settings.Height = System.Web.UI.WebControls.Unit.Pixel(550);
        settings.Styles.Content.Border.BorderWidth = 0;
        settings.TabPages.Add("所属用户组").SetContent(() =>
        {
            ViewContext.Writer.Write("<div id=\"userFunctreeLeft\" style=\"width: 50%; float: left; \">");
            @Html.DevExpress().TreeView(settingsGroupUser =>
            {
                settingsGroupUser.Name = "orgUserTree";
                settingsGroupUser.ShowTreeLines = true;
                settingsGroupUser.AllowSelectNode = true;
                settingsGroupUser.NameField = "Id";
                settingsGroupUser.TextField = "Name";
                settingsGroupUser.ImageUrlField = "ImageUrl";
                settingsGroupUser.CheckNodesRecursive = true;
                settingsGroupUser.AllowCheckNodes = true;
                settingsGroupUser.AllowSelectNode = false;
                settingsGroupUser.ClientSideEvents.Init = "function(s, e) { orgUserTreeInit(s,e) }";
                settingsGroupUser.EnableAnimation = false;
                settingsGroupUser.EnableClientSideAPI = true;
                settingsGroupUser.PreRender = (source, e) =>
                {
                    ASPxTreeView treeView = (ASPxTreeView)source;
                    treeView.ExpandAll();

                };
            }).Bind(ViewData["treeModelUserList"]).GetHtml();
            ViewContext.Writer.Write("</div>");
            ViewContext.Writer.Write("<div  id=\"userFunctreeRight\" style=\"width: 40%; float: left;\">");
            ViewContext.Writer.Write("<table cellpadding=\"0\" cellspacing=\"0\"><tr><td>当前用户已选菜单：</td></tr><tr><td><div  id=\"functionTree\" style=\"width:100%;height: 450px;margin:0\"></div></td></tr></table>");

            ViewContext.Writer.Write("</div>");
        });
        //settings.TabPages.Add("所属目录用户组").SetContent(() =>
        //{
        //    @Html.DevExpress().TreeView(settingsGroupUser =>
        //    {
        //        settingsGroupUser.Name = "functionTree";
        //        settingsGroupUser.ShowTreeLines = true;
        //        settingsGroupUser.AllowSelectNode = true;
        //        settingsGroupUser.NameField = "Id";
        //        settingsGroupUser.TextField = "Name";
        //        settingsGroupUser.ImageUrlField = "ImageUrl";
        //        settingsGroupUser.CheckNodesRecursive = true;
        //        settingsGroupUser.AllowCheckNodes = true;
        //        settingsGroupUser.AllowSelectNode = false;
        //        settingsGroupUser.ClientSideEvents.Init = "function(s, e) { functionTreeInit(s,e) }";
        //        settingsGroupUser.EnableAnimation = false;
        //        settingsGroupUser.EnableClientSideAPI = true;
        //        settingsGroupUser.PreRender = (source, e) =>
        //        {
        //            ASPxTreeView treeView = (ASPxTreeView)source;
        //            treeView.ExpandAll();

        //        };
        //    }).Bind(ViewData["treeModelFunctionList"]).GetHtml();
        //});
    }).GetHtml()

        @Html.Hidden("hdFunctionSelect", "");
        @Html.Hidden("hdOrgUserSelect", "");
        @Html.Hidden("hdMethod", ViewData["hdMethod"]);
        @Html.Hidden("hdResult", ViewData["result"]);
        @Html.Hidden("hdFLogIDEn", Model.FLogIDEn);
        @Html.Hidden("hdjsAlert", (ViewData["jsAlert"]));
        @Html.Hidden("hdgroupNos", (ViewData["groupNos"]));
@*        @Html.Hidden("hddirGroupNos", (ViewData["dirGroupNos"])); *@
        @Html.Hidden("hdFocusKey", ViewData["focusKey"]);
    }

    <script type="text/javascript" language="javascript">
        lp.Hide();
    </script>

</body>
</html>
